package cn.stylefeng.guns.modular.web.controller;

import cn.stylefeng.guns.core.ParamUtil;
import cn.stylefeng.guns.modular.rw.entity.BrankBannerTwo;
import cn.stylefeng.guns.modular.rw.entity.InfoSet;
import cn.stylefeng.guns.modular.rw.service.*;
import cn.stylefeng.roses.core.base.controller.BaseController;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 描述：品牌理念 controller
 * 作者：chenhuiyan
 * 时间：2020-05-08
 */
@Controller
@RequestMapping(value = "/web/brank")
public class WebBrankController extends BaseController {

    private String PREFIX = "/modular/web/";

    @Autowired
    private IInfoSetService infoSetService;

    @Autowired
    private IBrankBannerOneService brankBannerOneService;

    @Autowired
    private IBrankBannerTwoService brankBannerTwoService;

    @Autowired
    private IBrankBannerThreeService brankBannerThreeService;

    @Autowired
    private IBannerService bannerService;

    /**
     * 跳转到首页
     */
    @RequestMapping(value = "/")
    public String index() {
        return PREFIX + "brank.html";
    }

    /**
     * 初始化数据
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/getInitData")
    public Map<String, Object> getInitData(){
        Map<String, Object> res = new HashMap<>();

        Map<String, Object> params = ParamUtil.getParams();

        //查询基本配置
        InfoSet infoSet = infoSetService.getBaseMapper().selectList(new QueryWrapper<InfoSet>()).get(0);

        //查询品牌理念区块一
        Map<String, Object> brankBannerOne = brankBannerOneService.list(params).getRecords().get(0);

        //查询品牌理念区块二
        List<BrankBannerTwo> brankBannerTwoList = brankBannerTwoService.getBaseMapper().selectList(new QueryWrapper<BrankBannerTwo>().eq("is_show", 0));

        //查询品牌理念区块三
        Map<String, Object> brankBannerThree = brankBannerThreeService.list(params).getRecords().get(0);

        //banner品牌理念背景图
        params.put("webType", "1");
        Map<String, Object> banner = bannerService.list(params).getRecords().get(0);

        res.put("infoSet", infoSet);
        res.put("brankBannerOne", brankBannerOne);
        res.put("brankBannerTwoList", brankBannerTwoList);
        res.put("brankBannerThree", brankBannerThree);
        res.put("brankBannerThree", brankBannerThree);
        res.put("banner", banner);

        return res;
    }

}
